const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Schedule = sequelize.define('Schedule', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '调度任务名称'
  },
  type: {
    type: DataTypes.ENUM('device', 'system', 'custom'),
    defaultValue: 'custom',
    comment: '调度任务类型'
  },
  cronExpression: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '调度任务表达式'
  },
  action: {
    type: DataTypes.JSON,
    allowNull: false,
    comment: '调度任务执行动作'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive', 'error'),
    defaultValue: 'active',
    comment: '调度任务状态'
  },
  lastRunAt: {
    type: DataTypes.DATE,
    comment: '上次执行时间'
  },
  nextRunAt: {
    type: DataTypes.DATE,
    comment: '下次执行时间'
  },
  description: {
    type: DataTypes.TEXT,
    comment: '调度任务描述'
  },
  metadata: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '元数据'
  }
}, {
  comment: '调度任务信息表'
});

module.exports = Schedule; 